package com.mcflies.ui.drawable;

import java.io.InputStream;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;

import com.mcflies.commons.McfliesConstant;
import com.mcflies.ui.R;

public class DrawableStartStudyActivity extends Activity implements
		OnClickListener {
	private Button drawableStartStudy_Button_A, drawableStartStudy_Button_B,
			drawableStartStudy_Button_C, drawableStartStudy_Button_D,
			drawableStartStudy_Button_E;
	private ImageView drawableStartStudy_IV;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.android_drawable_start_study);
		initWidget();
		initClickEvent();
	}

	private void initClickEvent() {
		drawableStartStudy_Button_A.setOnClickListener(this);
		drawableStartStudy_Button_B.setOnClickListener(this);
		drawableStartStudy_Button_C.setOnClickListener(this);
		drawableStartStudy_Button_D.setOnClickListener(this);
		drawableStartStudy_Button_E.setOnClickListener(this);
	}

	private void initWidget() {
		drawableStartStudy_Button_A = (Button) findViewById(R.id.drawableStartStudy_Button_A);
		drawableStartStudy_Button_B = (Button) findViewById(R.id.drawableStartStudy_Button_B);
		drawableStartStudy_Button_C = (Button) findViewById(R.id.drawableStartStudy_Button_C);
		drawableStartStudy_Button_D = (Button) findViewById(R.id.drawableStartStudy_Button_D);
		drawableStartStudy_Button_E = (Button) findViewById(R.id.drawableStartStudy_Button_E);
		drawableStartStudy_IV = (ImageView) findViewById(R.id.drawableStartStudy_IV);
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.drawableStartStudy_Button_A:
			drawableStartStudy_IV.setBackgroundResource(R.drawable.a);
			break;
		case R.id.drawableStartStudy_Button_B:
			drawableStartStudy_IV.setBackgroundResource(R.drawable.b);
			break;
		case R.id.drawableStartStudy_Button_C:
			// Activity的父类ContextWrapper有这个setWallpaper方法，当然使用此方法需要有android.permission.SET_WALLPAPER权限
			try {
				InputStream stream = getResources().openRawResource(
						R.drawable.a);
				setWallpaper(stream);
			} catch (Exception e) {
				Log.i(McfliesConstant.MCFLIES_EXCEPTION_INFO_FLAG,
						e.getMessage());
			}
			break;
		case R.id.drawableStartStudy_Button_D:
			try {
				InputStream stream = getResources().openRawResource(
						R.drawable.b);
				setWallpaper(stream);
			} catch (Exception e) {
				Log.i(McfliesConstant.MCFLIES_EXCEPTION_INFO_FLAG,
						e.getMessage());
			}
			break;
		case R.id.drawableStartStudy_Button_E:
			try {
				// Activity的父类ContextWrapper有这个clearWallpaper方法，作用是恢复默认壁纸，当然使用此方法需要有android.permission.SET_WALLPAPER权限
				clearWallpaper();
			} catch (Exception e) {
				Log.i(McfliesConstant.MCFLIES_EXCEPTION_INFO_FLAG,
						e.getMessage());
			}
			break;
		}
	}
}
